package org.devocean.groupbuying.service.aspects;

import java.io.IOException;
import org.apache.solr.client.solrj.SolrServerException;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.devocean.groupbuying.domain.Deal;
import org.devocean.groupbuying.domain.Formula;
import org.devocean.groupbuying.domain.Plan;
import org.devocean.groupbuying.domain.Product;
import org.devocean.groupbuying.domain.Promotion;
import org.devocean.groupbuying.service.ExploredService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class ExplorerAspect {

	@Autowired
	private ExploredService exploredService;

	 @AfterReturning(pointcut =
	 "execution(* org.devocean.groupbuying.service.ProductService.addOrUpdateProduct(..))",
	 returning = "result")
	 public void afterAddOrUpdateProduct(JoinPoint joinPoint, Object result)
	 throws SolrServerException, IOException {
	 Product product = (Product) result;
	 exploredService.addOrUpdateExplored(product);
	 }
	
	
	 @AfterReturning(pointcut =
	 "execution(* org.devocean.groupbuying.service.PromotionService.addOrUpdatePromotion(..))",
	 returning = "result")
	 public void afterAddOrUpdatePromotion(JoinPoint joinPoint, Object result)
	 throws SolrServerException, IOException {
	 Promotion promotion = (Promotion) result;
	 exploredService.addOrUpdateExplored(promotion);
	
	 }
	
	 @AfterReturning(pointcut =
	 "execution(* org.devocean.groupbuying.service.DealService.addOrUpdateDeal(..))",
	 returning = "result")
	 public void afterAddOrUpdateDeal(JoinPoint joinPoint, Object result)
	 throws SolrServerException, IOException {
	 Deal deal = (Deal) result;
	 exploredService.addOrUpdateExplored(deal);
	 }
	
//	 @AfterReturning(pointcut =
//	 "execution(* org.devocean.groupbuying.service.DealService.addOrUpdateDeal(..))",
//	 returning = "result")
//	 public void afterAddOrUpdatePlan(JoinPoint joinPoint, Object result)
//	 throws SolrServerException, IOException {
//	 Plan plan = (Plan) result;
//	 exploredService.addOrUpdateExplored(plan);
//	 }
//	
//	 @AfterReturning(pointcut =
//	 "execution(* org.devocean.groupbuying.service.DealService.addOrUpdateDeal(..))",
//	 returning = "result")
//	 public void afterAddOrUpdateFormula(JoinPoint joinPoint, Object result)
//	 throws SolrServerException, IOException {
//	 Formula formula = (Formula) result;
//	 exploredService.addOrUpdateExplored(formula);
//	 }

}
